<!--
 * @Author: your name
 * @Date: 2020-12-03 11:44:37
 * @LastEditTime: 2021-02-03 14:39:07
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \solaxcloud\src\views\inventory\inventory.vue
-->
<template>
    <div class="inventory-main-box">
        <div class="search-box">
            <div class="search-box-sub">
                <span class="lable-text">{{$t('inventoryManage.barCode')}}</span>
                <el-input v-model="SN" style="width:160px;" :placeholder="$t('pleaseInput')"></el-input>
            </div>
            <div class="search-box-sub">
                <span class="lable-text">{{$t('firm')}}</span>
                <el-select v-model="firm" filterable :placeholder="$t('pleaseSelect')" clearable >
                    <el-option
                        v-for="item in dictionar.manufacturerList"
                        :key="item.sid"
                        :label="item.firmName"
                        :value="item.sid">
                    </el-option>
                </el-select>
            </div>
            <div class="search-box-sub">
                <span class="lable-text">{{$t('agent')}}</span>
                <el-select v-model="agent" filterable :placeholder="$t('pleaseSelect')" clearable >
                    <el-option
                        v-for="item in dictionar.agentList"
                        :key="item.sid"
                        :label="item.firmName"
                        :value="item.sid">
                    </el-option>
                </el-select>
            </div>
            <div class="search-box-sub">
                <span class="lable-text">{{$t('installer')}}</span>
                <el-select v-model="installer" filterable :placeholder="$t('pleaseSelect')" clearable >
                    <el-option
                        v-for="item in dictionar.installerList"
                        :key="item.sid"
                        :label="item.firmName"
                        :value="item.sid">
                    </el-option>
                </el-select>
            </div>
            <div class="search-box-sub">
                <span class="lable-text">{{$t('sn.snStatus')}}</span>
                <el-select v-model="inventoryStatus" filterable :placeholder="$t('pleaseSelect')" clearable >
                    <el-option
                        v-for="item in statusList"
                        :key="item.id"
                        :label="item.text"
                        :value="item.id">
                    </el-option>
                </el-select>
            </div>
            <div class="search-box-sub">
                <el-button type="primary" @click='query'>{{$t('query')}}</el-button>
            </div>
        </div>
        <div class="button-box">
            <el-button   type="primary" slot="reference"  icon='el-icon-download' class="marginR10" @click="()=>{$store.commit('setNewVisibleGroup',true)}">{{$t('inventoryManage.push')}}</el-button>
            <!-- v-if='getUserTypeFlag != "0"' -->
            <el-button v-if='getUserTypeFlag != "0"' type="primary" slot="reference"  icon='el-icon-download' class="marginR10" @click="()=>{$store.commit('setNewVisiblePvModules',true)}">{{$t('inventoryManage.pull')}}</el-button>
            <el-button v-if='getUserTypeFlag != "0"' type="primary" slot="reference"  icon='el-icon-download' class="marginR10" @click="()=>{$store.commit('setNewVisibleFlow',true)}">{{$t('inventoryManage.stockPullButtomMsg')}}</el-button>
        </div>
        <baseTable v-loading="loading"  row-key='sid' :data="dataRows" border  stripe :column='column' :select='true' @selection-change="handleSelectionChange($event)">
            <template #status='{data}'>
                    {{comm.returnCode(statusList,data.status,'id','text')}}
            </template>
            <template #storeNum='{data}' >
                    <span >{{returnNumber(data)}}</span>
            </template>
            <template #option="{data}">
                <div class="option-box">
                    <el-button size='small' type="primary" icon="el-icon-s-help"  @click='showRecord(data)' class="marginR10" :title='$t("inventoryManage.record")'></el-button>
                    
                    <el-button size='small' v-if='getUserTypeFlag == "0"' type="primary" icon="el-icon-tickets"  @click='showDetail(data)' class="marginR10" :title='$t("js_detail")'></el-button>
                    <el-popconfirm
                        :title="$t('confirmDelete')"
                        @confirm='deleteRow(data.sn)'
                        v-if='getUserTypeFlag == "0" && returnStatusNumber(data)'
                    >
                        <el-button class="marginR10" type="danger" slot="reference" icon='el-icon-delete' :title='$t("delete")'></el-button>
                    </el-popconfirm>
                    <el-button v-if='userType == 4 && data.status !=4' size='small' type="primary" icon="el-icon-success"  @click='showInstall(data)' class="marginR10" :title='$t("inventoryManage.recordInstall")'></el-button>
                </div>
            </template>
        </baseTable>
        <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="current"
        :page-sizes="[10, 20, 30, 50]"
        :page-size="size"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total">
        </el-pagination>
        <push @uploadData='query' :getUserTypeFlag='getUserTypeFlag' v-if='newVisibleGroup'></push>
        <pull @uploadData='query' :getUserTypeFlag='getUserTypeFlag' v-if='newVisiblePvModules'></pull>
        <stock @uploadData='query' :getUserTypeFlag='getUserTypeFlag' v-if='newVisibleFlow'></stock>
        <record @uploadData='query' :getUserTypeFlag='getUserTypeFlag' :returnStatusNumber='returnStatusNumber(editRow)' :editRow='editRow'></record>
        <detail @uploadData='query' :getUserTypeFlag='getUserTypeFlag' :returnStatusNumber='returnStatusNumber(editRow)' :editRow='editRow'></detail>
        <install @uploadData='query' :getUserTypeFlag='getUserTypeFlag' :returnStatusNumber='returnStatusNumber(editRow)' :editRow='editRow'></install>
    </div>
</template>

<script>
import baseTable from '../../components/common/baseTable'
import push from './inventory_push'
import pull from './inventory_pull'
import stock from './inventory_stock'
import record from './record'
import detail from './detail'
import install from './install'
export default {
    components: {
        baseTable,
        push,
        pull,
        stock,
        record,
        detail,
        install
    },
    props: {

    },
    data() {
        return {
            statusList:[{
                id:'3',
                text:this.$t('inventoryManage.statusWay')
            },{
                id:'1',
                text:this.$t('inventoryManage.statusNoWay')
            },{
                id:'2',
                text:this.$t('inventoryManage.stockTitle')
            },{
                id:'4',
                text:this.$t('inventoryManage.statusInstalled')
            }],
            SN:'',
            total:1,
            size:10,
            current:1,
            firm:'',
            agent:'',
            installer:'',
            inventoryStatus:'',
            dictionar:{},
            dataRows:[],
            column:[{
                title: this.$t('inventoryManage.barCode'),
                value: 'sn',
                slot: 'sn',
            },
            {
                title: this.$t('inventoryManage.Warehouse'),
                value: 'firmName',
                slot: 'firmName',
            },
            {
                title: this.$t('agent'),
                value: 'agentName',
                slot: 'agentName',
            },
            {
                title: this.$t('installer'),
                value: 'installerName',
                slot: 'installerName',
            },{
                title: this.$t('sn.snStatus'),
                value: 'status',
                slot: 'status',
            },{
                title: this.$t('inventoryManage.number') + this.$t('inventoryManage.tablePullOrPush'),
                value: 'storeNum',
                slot: 'storeNum',
            },
            {
                title: this.$t('control'),
                value: 'option',
                slot: 'option',
            }],
            loading:false,
            getUserTypeFlag:'0',
            editRow:{}
            
        };
    },
    computed: {
        userType(){
            return localStorage.getItem('userType')
        },
        newVisiblePvModules(){
            return this.$store.state.sysStore.newVisiblePvModules
        },
        newVisibleGroup(){
            return this.$store.state.sysStore.newVisibleGroup
        },
        newVisibleFlow(){
            return this.$store.state.sysStore.newVisibleFlow
        },
    },
    watch: {

    },
    created() {

    },
    mounted() {
        this.wmsproductinfoGetSearchFirmCondition()
        this.wmsproductinfoGetManufacturerType()
        this.wmsstockGetPage()
    },
    methods: {
        showInstall(data){
            this.editRow = data
            this.$store.commit('setRightVisibleEdit',true)
        },
        async deleteRow(sn){
            let res = await this.API.wmsproductinfoDelete({
                machineSN:sn
            })
            if(this.comm.showMsg(res.success)){
                this.wmsstockGetPage()
            }
        },
        //判断是否是料号
        returnStatusNumber(row){
            var flag = true
            if(row.recieveNum !== " - "||row.storeNum !== " - "||row.sendNum !== " - "){
                flag = false
            }
            return flag
        },
        async wmsproductinfoGetManufacturerType(){
            let res = await this.API.wmsproductinfoGetManufacturerType()
            this.getUserTypeFlag = res.object
        },
        showDetail(data){
            this.editRow = data
            this.$store.commit('setApiVisibleEdit',true)
        },
        showRecord(data){
            this.editRow = data
            this.$store.commit('setApiVisible',true)
        },
        returnNumber(row){
            row.recieveNum = row.recieveNum === null ?" - ":row.recieveNum
            row.storeNum = row.storeNum === null ?" - ":row.storeNum
            row.sendNum = row.sendNum === null ?" - ":row.sendNum
            let number = row.recieveNum +"/"+row.storeNum+"/"+row.sendNum
            return row.storeNum == ' - ' ? "-":number;
        },
        async wmsstockGetPage(){
            this.loading = true
            let arr = []
            if(this.firm){
                arr.push(this.firm)
            }
            if(this.agent){
                arr.push(this.agent)
            }
            if(this.installer){
                arr.push(this.installer)
            }
            let res = await this.API.wmsstockGetPage({
                sn:this.SN,
                status:this.inventoryStatus,
                firmId:this.firm,
                installerId:this.installer,
                agentId:this.agent,
                ids:JSON.stringify(arr),
                size:this.size,
                current:this.current
            })
            this.loading = false
            this.dataRows = res.rows || []
            this.total = res.total

        },
        async wmsproductinfoGetSearchFirmCondition(){
            let res = await this.API.wmsproductinfoGetSearchFirmCondition()
            this.dictionar = res.object
        },
        query(){
            this.current = 1
            this.wmsstockGetPage()
        },
        handleSizeChange(val) {
          this.size = val
          this.current = 1
          this.wmsstockGetPage()
        },
        handleCurrentChange(val) { 
          this.current = val
          this.wmsstockGetPage()
        },
        handleSelectionChange(val){
          this.selectDataList=val
        },
    },
};
</script>

<style  lang="less" scoped>
.inventory-main-box{
    
}
</style>
